package com.dynabook.oa.controller;


import cn.hutool.core.util.StrUtil;
import com.dynabook.oa.common.BaseResponse;
import com.dynabook.oa.common.ErrorCode;
import com.dynabook.oa.common.ResultUtils;
import com.dynabook.oa.model.dto.CheckOADTO;
import com.dynabook.oa.model.dto.CheckOAFirstDTO;
import com.dynabook.oa.model.vo.CheckOAFirstVO;
import com.dynabook.oa.model.vo.CheckOASecondVO;
import com.dynabook.oa.service.EclOaRequestStatusService;
import com.dynabook.oa.service.EclOaToPcsDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@Slf4j
public class OAController {


    @Resource
    private EclOaRequestStatusService eclOaRequestStatusService;

    @Resource
    private EclOaToPcsDetailService eclOaToPcsDetailService;


    @PostMapping("checkOAFirst")
    public BaseResponse<CheckOAFirstVO> checkOAFirst(@NotNull  @RequestBody CheckOAFirstDTO checkOAFirstDTO) {
        String requestId = checkOAFirstDTO.getRequestId();
        if (StrUtil.isBlank(requestId)) {
            log.error("checkOAFirst,参数为:{},requestId为空",checkOAFirstDTO);
            return  ResultUtils.error(ErrorCode.PARAMS_ERROR,"requestId不能为空");
        }
        return ResultUtils.success(eclOaRequestStatusService.checkOAFirst(requestId));
    }

    @PostMapping("checkOASecond")
    public BaseResponse<CheckOASecondVO> checkOASecond(@Valid  @RequestBody CheckOADTO checkOADTO) {
        CheckOASecondVO checkOASecondVO=eclOaToPcsDetailService.checkOASecond(checkOADTO);
        return ResultUtils.success(checkOASecondVO);
    }

    @PostMapping("updateFlag")
    public BaseResponse<String> updateFlag(@NotNull  @RequestBody List<Long> ids) {
        Boolean result=eclOaToPcsDetailService.updateFlag(ids);
        return ResultUtils.success(result?"更新成功":"更新失败");
    }



}
